package edu.gdkm.dao;

import edu.gdkm.pojo.Education;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface EducationDao {

    // 根据ID查询
    @Select("SELECT * FROM Educations WHERE education_id = #{educationId}")
    Education selectById(Integer educationId);

    // 根据简历ID查询
    @Select("SELECT * FROM Educations WHERE resume_id = #{resumeId} ORDER BY start_date DESC")
    List<Education> selectByResumeId(Integer resumeId);

    // 查询所有
    @Select("SELECT * FROM Educations")
    List<Education> selectAll();

    // 新增
    @Insert("INSERT INTO Educations(resume_id, institution_name, degree, field_of_study, start_date, end_date, " +
            "is_current, description, location, gpa) " +
            "VALUES(#{resumeId}, #{institutionName}, #{degree}, #{fieldOfStudy}, #{startDate}, #{endDate}, " +
            "#{isCurrent}, #{description}, #{location}, #{gpa})")
    @Options(useGeneratedKeys = true, keyProperty = "educationId")
    int insert(Education education);

    // 更新
    @Update("UPDATE Educations SET resume_id = #{resumeId}, institution_name = #{institutionName}, degree = #{degree}, " +
            "field_of_study = #{fieldOfStudy}, start_date = #{startDate}, end_date = #{endDate}, " +
            "is_current = #{isCurrent}, description = #{description}, location = #{location}, " +
            "gpa = #{gpa} WHERE education_id = #{educationId}")
    int update(Education education);

    // 删除
    @Delete("DELETE FROM Educations WHERE education_id = #{educationId}")
    int delete(Integer educationId);
    
    // 根据简历ID删除
    @Delete("DELETE FROM Educations WHERE resume_id = #{resumeId}")
    int deleteByResumeId(Integer resumeId);
}
    